ng911ok.lib.counties module#
- class CountyInfo(state: str, name: str, fips3: str, number: int | None = None)#
Bases:
objectProvides some basic information about counties based on the data in
counties.yml. The class methodload()automatically reads in the data from that YAML file and returns aFrozenListofCountyInfoinstances, while the class methodload_df()provides that information as apandas.DataFrame.When sorted, instance of this class are arranged alphabetically by their
state, then byname, then byfips3, then bynumber.- classmethod _yaml_from_feature_class(input_fc: Path, output_yaml: Path, name_field: str, fips_field: str, number_field: str | None = None, state_field: str | None = None, default_state: str | None = None) Path#
Generates
counties.ymlbased on a feature class containing the relevant data.Warning
This method will, without confirmation, overwrite the file located at output_yaml, should one already exist.
- Parameters:
input_fc (pathlib.Path) – Feature class containing relevant data
output_yaml (pathlib.Path) – Path to which the generated YAML will be written
name_field (str) – Name of the county name field in input_fc
fips_field (str) – Name of the three-digit FIPS code field in input_fc
number_field (Optional[str]) – Name of the state-assigned county number field in input_fc
state_field (Optional[str]) – Name of the state field in input_fc
default_state (Optional[str]) – State to use for all records generated in lieu of a state_field
- Returns:
Path to the generated YAML file
- Return type:
pathlib.Path
- classmethod get_county(name: str | None = None, state: str | None = None, *, fips3: str | int | None = None, number: int | None = None) Self#
Returns the
CountyInfoobject matching the supplied criteria.Exactly one of name, fips3, or number is required. If multiple counties match based on the given criterion of those three options, the state argument will be used to filter further. If a state argument is needed but absent, or if the number of candidates is not exactly one, a
LookupErrorwill be raised.In the case of name, a space followed by the jurisdiction type name, e.g., “COUNTY”, is automatically removed. If state is provided,
_county_equivalent_nameswill be used to determine the term to strip. If state is not provided,_county_equivalent_name_defaultwill be used.- Parameters:
name (Optional[str]) – Name of the county to search for
state (Optional[str]) – Name of the state containing the desired county
fips3 (Optional[str | int]) – Three-digit FIPS code for the desired county
number (Optional[int]) – The state-assigned county number of the desired county
- Returns:
The county matching the supplied criteria
- Return type:
- classmethod load() FrozenList[Self]#
Loads and returns all
CountyInfoobjects represented incounties.yml.
- classmethod load_df() DataFrame#
Loads and returns all
CountyInfoobjects represented incounties.ymlas apandas.DataFrame. The resulting data frame will have the following columns anddtypes:state-string[python]name-string[python]fips3-string[python]number-Int64
- _county_equivalent_name_default: ClassVar[str] = 'COUNTY'#
Term used by default to refer to county-equivalent jurisdictions in computing
full_name. Overridden for individual states in_county_equivalent_names.
- _county_equivalent_names: ClassVar[dict[str, str]] = {}#
Mapping of state name (
state) to the term used locally for county-equivalent jurisdictions, e.g.,{"LOUISIANA": "PARISH"}. For states not included in this dict, the string in_county_equivalent_name_defaultwill be used byfull_name.
- fips3: str#
Three-digit FIPS code for the county.
- property full_name: str#
- name: str#
Name of the county (uppercase).
- number: int | None#
State-assigned county number for the county.
- state: str#
State in which the county lies (uppercase).
- class CountyInfoDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)#
Bases:
DumperClass used in the process of generating
counties.yml.- represent_data(data)#